
import cn.hutool.core.lang.Pair;
import cn.hutool.core.swing.RobotUtil;
import cn.hutool.core.util.RandomUtil;

import java.util.Random;


public class RobotTest {
    private static final Random RANDOM = new Random();

    //使用mumu模拟器，打开阴阳师，将窗口放缩成(0,0)到(671,412)大小（或者可以自己设置，用picpick像素尺可以自己量）
    public static void main(String[] args) {
        test1();
    }

    // 御灵本
    public static void test1() {
        //缩小当前窗口
        RobotUtil.mouseMove(1804, 14); // 移动鼠标到坐标(-600, 600)
        RobotUtil.click();
        while (true) {
            Pair<Integer, Integer> index = randomIndexCircle(601, 367, 17);
            RobotUtil.mouseMove(index.getKey(), index.getValue()); // 移动鼠标到坐标(-600, 600)
            RobotUtil.click();
            double v = RandomUtil.randomDouble(3);
            RobotUtil.setDelay((int) (16 * 1000 + v * 1000));
            Pair<Integer, Integer> index2 = randomIndexCircle(601, 367, 17);
            RobotUtil.mouseMove(index2.getKey(), index2.getValue()); // 移动鼠标到坐标(-600, 600)
            RobotUtil.click();
            double v3 = RandomUtil.randomDouble(1);
            RobotUtil.setDelay((int) (600 + v3 * 1000));
            Pair<Integer, Integer> index3 = randomIndexCircle(601, 367, 17);
            RobotUtil.mouseMove(index3.getKey(), index3.getValue()); // 移动鼠标到坐标(-600, 600)
            double v4 = RandomUtil.randomDouble(1);
            RobotUtil.setDelay((int) (1500 + v4 * 1000));
            RobotUtil.click();
            double v5 = RandomUtil.randomDouble(1);
            RobotUtil.setDelay((int) (1000 + v5 * 1000));
        }
    }

    // 活动本
    public static void test2() {
        RobotUtil.mouseMove(1804, 14); // 移动鼠标到坐标(-600, 600)
        RobotUtil.click();
        while (true) {
            Pair<Integer, Integer> index = randomIndexCircle(617, 365, 17);
            RobotUtil.mouseMove(index.getKey(), index.getValue()); // 移动鼠标到坐标(-600, 600)
            RobotUtil.click();
            double v = RandomUtil.randomDouble(3);
            RobotUtil.setDelay((int) (12 * 1000 + v * 1000));
            Pair<Integer, Integer> index2 = randomIndexCircle(617, 365, 30);
            RobotUtil.mouseMove(index2.getKey(), index2.getValue()); // 移动鼠标到坐标(-600, 600)
            RobotUtil.click();
            double v3 = RandomUtil.randomDouble(1);
            RobotUtil.setDelay((int) (600 + v3 * 1000));
            Pair<Integer, Integer> index3 = randomIndexCircle(617, 365, 30);
            RobotUtil.mouseMove(index3.getKey(), index3.getValue()); // 移动鼠标到坐标(-600, 600)
            double v4 = RandomUtil.randomDouble(1);
            RobotUtil.setDelay((int) (600 + v4 * 1000));
            RobotUtil.click();
            double v5 = RandomUtil.randomDouble(1);
            RobotUtil.setDelay((int) (1500 + v5 * 1000));
        }
    }

    /**
     * 矩形
     */
    public static Pair<Integer, Integer> randomIndexRectangle(Integer x, Integer y, Integer offsetRangeX, Integer offsetRangeY) {
        int i = RandomUtil.randomInt(2 * offsetRangeX) - offsetRangeX;
        int j = RandomUtil.randomInt(2 * offsetRangeY) - offsetRangeY;
        return Pair.of(x + i, y + j);
    }

    /**
     * 正方形
     */
    public static Pair<Integer, Integer> randomIndexSquare(Integer x, Integer y, Integer offsetRange) {
        return randomIndexRectangle(x, y, offsetRange, offsetRange);
    }

    /**
     * 圆形
     */
    public static Pair<Integer, Integer> randomIndexCircle(Integer x, Integer y, Integer offsetRange) {
        // 随机生成半径r和角度θ
        double angle = 2 * Math.PI * RANDOM.nextDouble();
        double r = offsetRange * Math.sqrt(RANDOM.nextDouble());
        return Pair.of((int) Math.round(x + r * Math.cos(angle)), (int) Math.round(y + r * Math.sin(angle)));
    }
}